package com.ruoyi.statistics.service.impl;


import com.ruoyi.common.helper.LoginHelper;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.customer.service.IGradeConfigService;
import com.ruoyi.statistics.domain.RevenueStatistics;
import com.ruoyi.statistics.mapper.StatisticsMapper;
import com.ruoyi.statistics.service.IStatisticsService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@RequiredArgsConstructor
@Service
public class StatisticsServiceImpl implements IStatisticsService {

    private final StatisticsMapper statisticsMapper;

    private final IGradeConfigService gradeConfigService;


    @Override
    public List<RevenueStatistics> selectTeamRevenueList(RevenueStatistics revenueStatistics) {
        return statisticsMapper.selectTeamRevenueListChange(revenueStatistics);
    }


    @Override
    public List<RevenueStatistics> selectUserRevenueList(RevenueStatistics revenueStatistics) {
        return statisticsMapper.selectUserRevenueListChange(revenueStatistics);
    }

    @Override
    public RevenueStatistics selectUserRevenueTotalMonth() {
        RevenueStatistics revenueStatistics = new RevenueStatistics();
        revenueStatistics.setUserId(LoginHelper.getUserId());
        revenueStatistics.setDeptId(LoginHelper.getDeptId());
        RevenueStatistics revenueStatistics1 = statisticsMapper.selectUserRevenueTotalMonthChange(revenueStatistics);
        String revenue = revenueStatistics1.getRevenue();
        if (StringUtils.isNotBlank(revenue)) {
            Map<String, String> map = gradeConfigService.gradeInfo(revenue);
            revenueStatistics1.setGradeType(map.get("grade"));
            revenueStatistics1.setGradeName(map.get("gradeName"));
        }
        return revenueStatistics1;
    }

}
